using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using DevExpress.XtraEditors;

namespace TCCT_CTC_CSDLDangVienV1
{
    /// <summary>
    /// User Interface class
    /// </summary>
    public static partial class UI
    {
        public static Color HIGHLIGHT_COLOR = Color.Gold;
        public static Color DEFAULT_BACKCOLOR = Color.White;
        public static Color DISABLED_COLOR = Color.LightGray;
        public static Color NOT_NULL_COLOR = Color.LightSkyBlue;
        public static Color READ_ONLY_COLOR = Color.LightGreen;
        public static Color LABEL_COLOR = Color.Transparent;
        public static Color FIND_BACKCOLOR = Color.PaleGreen;

        #region FOR GRID

        public static Color GRID_FIXED_LINE_COLOR = Color.RoyalBlue;
        public static Color GRID_GROUP_PANEL_COLOR_1 = Color.NavajoWhite;
        public static Color GRID_GROUP_PANEL_COLOR_2 = Color.Orange;

        #endregion FOR GRID

        #region DisableControl

        /// <summary>
        /// Disables the control.
        /// </summary>
        /// <param name="control">The control.</param>
        public static void DisableControl(BaseControl control)
        {
            control.Enabled = false;
        }

        /// <summary>
        /// Enable the control
        /// </summary>
        /// <param name="control"></param>
        public static void EnableControl(BaseControl control)
        {
            control.Enabled = true;
        }

        public static void SetEnable(Control control, bool enabled)
        {
            control.Enabled = enabled;
        }

        #endregion DisableControl

        #region ApplyNotNull

        public static void ApplyNotNull(Control control)
        {
            foreach (Control ctr in control.Controls)
            {
                if (ctr.Name.IndexOf("_") == 0)
                    ctr.BackColor = NOT_NULL_COLOR;
            }
        }

        public static void ApplyNotNull(BaseEdit control)
        {
            control.BackColor = NOT_NULL_COLOR;
        }

        public static void ApplyNotNull(TextEdit control)
        {
            control.BackColor = NOT_NULL_COLOR;
        }

        public static void ApplyNotNull(DevExpress.XtraEditors.ButtonEdit control)
        {
            control.BackColor = NOT_NULL_COLOR;
        }

        public static void ApplyNotNull(DateEdit control)
        {
            control.BackColor = NOT_NULL_COLOR;
        }

        public static void ApplyNotNull(ComboBoxEdit control)
        {
            control.BackColor = NOT_NULL_COLOR;
        }

        public static void ApplyNotNull(ListBoxControl control)
        {
            control.BackColor = NOT_NULL_COLOR;
        }

        #endregion ApplyNotNull

        #region SetFocus

        /// <summary>
        /// Sets the focus to the control
        /// </summary>
        /// <param name="control">The control.</param>
        public static void SetFocus(object control)
        {
            try
            {
                BaseEdit baseEdit = (BaseEdit)control;
                baseEdit.Focus();
                baseEdit.SelectAll();
            }
            catch { }
        }

        /// <summary>
        /// Handles the focus event of the control
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public static void HandleFocusEvent(object sender, EventArgs e)
        {
            try
            {
                BaseEdit baseEdit = (BaseEdit)sender;
                baseEdit.SelectAll();
            }
            catch { }
        }

        #endregion SetFocus

        #region Read-Only

        /// <summary>
        /// Sets the read only.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="readOnly">if set to <c>true</c> [read only].</param>
        public static void SetReadOnly(BaseEdit control, bool readOnly)
        {
            control.Properties.ReadOnly = readOnly;
            control.TabStop = !readOnly;
        }

        public static void SetReadOnly(BaseEdit control)
        {
            SetReadOnly(control, true);
        }
        //public static void SetReadOnly(Control control, bool readOnly)
        //{
        //    foreach (Control ctr in control.Controls)
        //    {
        //        if (ctr.Name.IndexOf("_") == 0)
        //        {
        //            ((BaseEdit)ctr).Properties.ReadOnly = readOnly;
        //            ctr.TabStop = !readOnly;
        //        }
        //    }
        //}

        //public static void SetReadOnly(Control control)
        //{
        //    SetReadOnly(control, true);
        //}


        #endregion Read-Only

        public static void ApplyFind(ComboBoxEdit control)
        {

            control.BackColor = FIND_BACKCOLOR;
        }
        public static void ApplyFind(LookUpEdit control)
        {

            control.BackColor = FIND_BACKCOLOR;
        }
    }
}
